#include <stdio.h>
#define N 100001
int queue[N],*front=queue, *back=queue;
int main() {
	int n,a;
	scanf("%d", &n);
	while(n--) {
		scanf("%d",&a);
		switch(a){
			case 1:
				scanf("%d", &a);
				*++back=a;
				break;
			case 2:
				front++;break;
			case 3:
				printf("%d\n",*(front+1));break;
		}
	}
	return 0;
}
